CXXFLAGS =	-O2 -g -Wall -fmessage-length=0

# to add a new object put it into OBJS

# when adding a new object test 
# 1) move the tested object from OBJS to TEST_OBJS
# 2) add a reference to it's .o file in TEST_OBJS and TEST_OBJS_ALT
# 3) add a reference to it's .c file in TESTS

OBJS =		Stringline.o hw2.tab.o lex.yy.o semantics/semantics.o \
	 			$(TEST_OBJS)
	
TEST_OBJS = string/String.o semantics/LookupTable.o \
				semantics/AnonymousStatement.o semantics/Argument.o \
				log/Log.o file/File.o semantics/reservedWords.o

TEST_OBJS_ALT = ../string/String.o ../semantics/LookupTable.o \
				../semantics/AnonymousStatement.o ../semantics/Argument.o \
				../log/Log.o ../file/File.o ../semantics/reservedWords.o

LIBS =		gc6.7/gc.a

TARGET =	Stringline.exe

ZIP_FILE = ../Hw2.zip

FLEX_FILES = lex.yy.c

BISON_FILES = hw2.tab.c hw2.tab.h hw2.tab.h.gch

TEST_FILES = tests/test.exe tests/AllTests.c

TESTS = ParserTest.c StringTest.c LookupTableTest.c AnonymousStatementTest.c \
			ArgumentTest.c LogTest.c FileTest.c reservedWordsTest.c

$(TARGET):	$(OBJS) $(LIBS)
	@echo "***LINKING! Creating $(TARGET)"
	cc -o $(TARGET) $(OBJS) $(LIBS)
	@echo "***Created $(TARGET)"

.PHONY:all
all:	$(TARGET) 

lex.yy.o: lex.yy.c
	@echo "***Creating  lex.yy.o"
	cc -c lex.yy.c
	@echo "***Completed lex.yy.o"

lex.yy.c:
	@echo "***Creating lex.yy.c"
	flex hw2.l
	@echo "***Created lex.yy.c"
	
hw2.tab.o: hw2.tab.c hw2.tab.h lex.yy.c
	@echo "***Creating  hw2.tab.o"
	cc -c lex.yy.c hw2.tab.c hw2.tab.h 
	@echo "***Created   hw2.tab.o"
	
Stringline.o: hw2.tab.h
	cc    -c -o Stringline.o Stringline.c

hw2.tab.c:
	@echo "***Creating hw2.tab.c"
	bison -d hw2.y
	@echo "***Created hw2.tab.c"
	
hw2.tab.h:
	@echo "***Creating hw2.tab.h"
	bison -d hw2.y
	@echo "***Created hw2.tab.h"
	
tests/AllTests.c:
	@echo "***Creating tests/AllTests.c" 
	cd tests;./make-tests.sh > AllTests.c
	@echo "***Created tests/AllTests.c"
	
gc6.7/gc.a:
	cd gc6.7; make all
	
../gc6.7/gc.a:
	cd gc6.7; make all

.PHONY:clean
clean:
	rm -f $(OBJS) $(TARGET) $(FLEX_FILES) $(BISON_FILES) \
		$(TEST_FILES) *.stackdump $(ZIP_FILE) gc6.7/cord/cordtest.exe
	cd gc6.7; make clean

zip:
	make clean
	cd ..;zip -r -x@Hw2/exclude.txt Hw2.zip Hw2/
	
submit:
	firefox https://www.cs.sjsu.edu/faculty/pollett/152.1.08f/?submit.shtml?Sec0?Monday,%2022-Sep-2008%2015:08:27%20PDT
	
cycle:
	make clean
	make test
	
test: tests/AllTests.c tests/AllTests.o $(TEST_OBJS) $(LIBS) ../gc6.7/gc.a
	@echo "***Creating tests"
	cd tests; cc -o test.exe AllTests.c CuTest.c $(TESTS) $(TEST_OBJS_ALT) ../gc6.7/gc.a
	make all
	@echo "***Running gc6.7 tests"
	cd gc6.7; make test
	@echo "***Running HW2 tests"
	-./tests/test.exe
	@echo "***Testing Complete"
